home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / bitmapBrowserWindow.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  12.5 KB  |  478 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  07 Feb 2001
  22. //  Author:         bwk
  23. //
  24. //  Description:
  25. //        This file implements a generic bitmap browser for all platforms.
  26. //        Note however that the current NT implementation consists of calling
  27. //        the xpmPicker command. Most of the procedures below are for the
  28. //        Irix implementation.
  29. //
  30.  
  31. proc string getDirectory()
  32. //
  33. //    Description:
  34. //        Return the current directory.
  35. //
  36. {
  37.     setParent BitmapBrowserWindow;
  38.  
  39.     string $directory;
  40.     
  41.     $directory = `finder -query -filePath BitmapBrowserWindowFinder`;
  42.  
  43.     //    Make sure the last character is a "/". 
  44.     //
  45.     if (!`gmatch $directory "*/"`) {
  46.         $directory += "/";
  47.     }
  48.  
  49.     return $directory;
  50. }
  51.  
  52. proc string getBitmapSelection()
  53. //
  54. //    Description:
  55. //        Return the current bitmap selection. May return an empty string if
  56. //        there is no selection in the file list.
  57. //
  58. {
  59.     setParent BitmapBrowserWindow;
  60.  
  61.     string $selection[], $bitmap = "";
  62.  
  63.     $selection = `textScrollList -query -selectItem
  64.         BitmapBrowserWindowDirectoryList`;
  65.     
  66.     if ("" != $selection[0]) {
  67.         $bitmap = (getDirectory() + $selection[0]);
  68.     }
  69.  
  70.     return $bitmap;
  71. }
  72.  
  73. proc updateDirectoryList(string $bitmap)
  74. //
  75. //    Description:
  76. //        Update the file list control based on the current directory.
  77. //
  78. {
  79.     string $directory, $bitmapArray[], $xpmArray[], $bmpArray[];
  80.     int    $index, $selectIndex = 0;
  81.  
  82.     setParent BitmapBrowserWindow;
  83.  
  84.     //    Remove all the items in the file list control.
  85.     //
  86.     textScrollList -edit -removeAll BitmapBrowserWindowDirectoryList;
  87.  
  88.     //    Get the current directory.
  89.     //
  90.     $directory = getDirectory();
  91.  
  92.     //    Get all bitmap files in the directory.
  93.     //
  94.     $xpmArray = `getFileList -folder $directory -filespec "*.xpm"`;
  95.     $bmpArray = `getFileList -folder $directory -filespec "*.bmp"`;
  96.  
  97.     //    Combine the two lists and sort if necessary.
  98.     //
  99.     int $sort = false;
  100.     if (0 == size($xpmArray)) {
  101.         $bitmapArray = $bmpArray;
  102.         $sort = false;
  103.     } else if (0 == size($bmpArray)) {
  104.         $bitmapArray = $xpmArray;
  105.         $sort = false;
  106.     } else {
  107.         $bitmapArray =  AWAppendStringsToStringArray($xpmArray, $bmpArray);
  108.         $sort = true;
  109.     }
  110.     if ($sort) $bitmapArray = sort($bitmapArray);
  111.  
  112.     //    Turn on the wait cursor if we have a lot of bitmaps to list.
  113.     //
  114.     if (100 < size($bitmapArray)) waitCursor -state on;
  115.  
  116.     //    Append each bitmap to the list.
  117.     //
  118.     for ($index = 0; $index < size($bitmapArray); $index++) {
  119.         textScrollList -edit -append $bitmapArray[$index]
  120.             BitmapBrowserWindowDirectoryList;
  121.  
  122.         //    See if the argument bitmap is in the list. If so then
  123.         //    record the index so we can scroll the list to show it.
  124.         //
  125.         if ($bitmap == $bitmapArray[$index]) $selectIndex = $index + 1;
  126.     }
  127.  
  128.     if (0 < $selectIndex) {
  129.         //
  130.         //    Select the argument bitmap and scroll the list so it is visible.
  131.         //
  132.         textScrollList -edit
  133.             -selectItem $bitmap
  134.             -showIndexedItem $selectIndex
  135.             BitmapBrowserWindowDirectoryList;
  136.     }
  137.  
  138.     //    Turn off the wait cursor.
  139.     //
  140.     if (100 < size($bitmapArray)) waitCursor -state off;
  141. }
  142.  
  143. proc updatePreview()
  144. //
  145. //    Description:
  146. //        Update the preview image based on the selected bitmap.
  147. //
  148. {
  149.     string $bitmap;
  150.     int    $visible = false;
  151.     
  152.     setParent BitmapBrowserWindow;
  153.  
  154.     //    Get the current bitmap selection.
  155.     //
  156.     $bitmap = getBitmapSelection();
  157.  
  158.     //    If there is no bitmap selected then make sure the image reflects this.
  159.     //    Since we can't unassign a bitmap from a control just hide it.
  160.     //
  161.     if ("" != $bitmap) $visible = true;
  162.  
  163.     iconTextStaticLabel -edit
  164.         -image1 $bitmap
  165.         -visible $visible
  166.         BitmapBrowserWindowPreviewImage;
  167. }
  168.  
  169. proc bitmapBrowserWindowClose()
  170. //
  171. //    Description:
  172. //        Safely delete the browser window.
  173. //
  174. {
  175.     evalDeferred("deleteUI -window BitmapBrowserWindow");
  176. }
  177.  
  178. global proc bitmapBrowserWindow(
  179.     string $bitmap,
  180.     string $callbackProcedure)
  181. //
  182. //    Description:
  183. //        Show the bitmap browser window.
  184. //
  185. //
  186. //    Arguments:
  187. //        $bitmap - The name of the bitmap that you want initially selected
  188. //                  in the browser.
  189. //
  190. //        $callbackProcedure - The procedure that will be called when a bitmap
  191. //                             is selected or the the browser is dismissed.
  192. //                             The procedure must be defined as follows:
  193. //
  194. //            global proc yourCallbackProcedure(
  195. //                string $bitmap, // Full path to selected bitmap.
  196. //                int    $status  // Status of selection, currently unused.
  197. //                )
  198. //
  199. //    Notes:
  200. //        On NT this simply calls the xpmPicker command which posts a modal
  201. //        dialog.
  202. //
  203. //        On Irix we create our own window and manage all of the controls.
  204. //
  205. {
  206.     if (`about -nt`) {
  207.         string $result = `xpmPicker -fileName $bitmap`;
  208.         int    $status = 0;
  209.  
  210.         if ("" != $callbackProcedure) {
  211.             eval ($callbackProcedure + " \"" + $result + "\" " + $status);
  212.         }
  213.     }else if(`about -mac`){
  214.         string $result;
  215.         string $dirName = getenv("MAYA_LOCATION");
  216.         string $matchExpr = "Maya.app/Contents";
  217.         
  218.         string $myString = `substitute $matchExpr $dirName ""`;
  219.         int    $status = 0;
  220.     
  221.         $dirName = $myString + "Application Support/extras/icons";
  222.         $dirName = $dirName+"/*.xpm";
  223.         $result = `fileDialog -dm  $dirName`;
  224.         if ($result == "") return; // cancel hit
  225.         
  226.         if ("" != $callbackProcedure) {
  227.             eval ($callbackProcedure + " \"" + $result + "\" " + $status);
  228.         }
  229.  
  230.     } else {
  231.         if (!`window -exists BitmapBrowserWindow`) {
  232.         
  233.             waitCursor -state on;
  234.  
  235.             string $window = `window -title "Bitmap Browser"
  236.                 -iconName "Bitmaps"
  237.                 BitmapBrowserWindow`;
  238.  
  239.             string $form = `formLayout`;
  240.  
  241.             setParent $form;
  242.             string $optionMenu = `optionMenu BitmapBrowserWindowDirectoryOptionMenu`;
  243.             string $finder = `finder -addDropBox false BitmapBrowserWindowFinder`;
  244.             string $bodyForm = `formLayout`;
  245.             string $list = `textScrollList BitmapBrowserWindowDirectoryList`;
  246.             string $frame = `frameLayout -labelVisible false`;
  247.             string $preview = `iconTextStaticLabel -width 128 -height 128
  248.                 BitmapBrowserWindowPreviewImage`;
  249.  
  250.             setParent $form;
  251.             string $buttonForm = `formLayout`;
  252.             string $select = `button -label "Select"`;
  253.             string $cancel = `button -label "Cancel"`;
  254.  
  255.             formLayout -edit
  256.                 -attachForm     $select     "top"    0
  257.                 -attachForm     $select     "left"   0
  258.                 -attachForm     $select     "bottom" 0
  259.                 -attachPosition $select     "right"  2 50
  260.  
  261.                 -attachForm     $cancel     "top"    0
  262.                 -attachPosition $cancel     "left"   2 50
  263.                 -attachForm     $cancel     "bottom" 0
  264.                 -attachForm     $cancel     "right"  0
  265.                 $buttonForm;
  266.  
  267.             formLayout -edit
  268.                 -attachForm     $list       "top"    0
  269.                 -attachForm     $list       "left"   0
  270.                 -attachForm     $list       "bottom" 0
  271.                 -attachControl  $list       "right"  4 $frame
  272.  
  273.                 -attachForm     $frame      "top"    0
  274.                 -attachNone     $frame      "left"
  275.                 -attachNone     $frame      "bottom"
  276.                 -attachForm     $frame      "right"  0
  277.                 $bodyForm;
  278.  
  279.             formLayout -edit
  280.                 -attachForm     $optionMenu "top"    4
  281.                 -attachForm     $optionMenu "left"   4
  282.                 -attachNone     $optionMenu "bottom"
  283.                 -attachForm     $optionMenu "right"  4
  284.  
  285.                 -attachControl  $finder     "top"    4 $optionMenu
  286.                 -attachForm     $finder     "left"   4
  287.                 -attachNone     $finder     "bottom"
  288.                 -attachForm     $finder     "right"  4
  289.  
  290.                 -attachControl  $bodyForm   "top"    4 $finder
  291.                 -attachForm     $bodyForm   "left"   4
  292.                 -attachControl  $bodyForm   "bottom" 4 $buttonForm
  293.                 -attachForm     $bodyForm   "right"  4
  294.  
  295.                 -attachNone     $buttonForm "top"
  296.                 -attachForm     $buttonForm "left"   4
  297.                 -attachForm     $buttonForm "bottom" 4
  298.                 -attachForm     $buttonForm "right"  4
  299.                 $form;
  300.  
  301.             //    Populate the option menu with the bitmap directories.
  302.             //
  303.             string $directory, $directoryArray[];
  304.             $directoryArray = `xbmLangPathList`;
  305.             for ($directory in $directoryArray) {
  306.                 menuItem -label $directory;
  307.             }
  308.  
  309.             //
  310.             //    Attach control commands.
  311.             //
  312.             optionMenu -edit -changeCommand ("bitmapBrowserWindowDirectoryMenuChange") $optionMenu;
  313.             finder -edit
  314.                 -filePath $directoryArray[0]
  315.                 -command ("bitmapBrowserWindowFinderChange")
  316.                 $finder;
  317.  
  318.             textScrollList -edit -selectCommand ("bitmapBrowserWindowListSelect") $list;
  319.  
  320.             button -edit -command ("bitmapBrowserWindowCancel \"" + $callbackProcedure + "\"") $cancel;
  321.             button -edit -command ("bitmapBrowserWindowSelect \"" + $callbackProcedure + "\"") $select;
  322.  
  323.             //    See if the supplied bitmap exists. If so then make sure it is
  324.             //    selected.
  325.             //
  326.             $directory = locateBitmap($bitmap);
  327.             if ("" != $directory) {
  328.                 optionMenu -edit -value $directory $optionMenu;
  329.                 finder -edit -filePath $directory $finder;
  330.             }
  331.  
  332.             waitCursor -state off;
  333.  
  334.             updateDirectoryList($bitmap);
  335.             updatePreview();
  336.  
  337.             showWindow $window;
  338.  
  339.         } else {
  340.             //    Window already exists.
  341.             showWindow BitmapBrowserWindow;
  342.         }
  343.     }
  344. }
  345.  
  346. global proc string locateBitmap(string $bitmap)
  347. //
  348. //    Description:
  349. //        Find the directory location of a bitmap. The directories searched
  350. //        are specified by the XBMLANGPATH environment variable.
  351. //
  352. //    Arguments:
  353. //        $bitmap - The name of the bitmap to search for.
  354. //
  355. //    Returns:
  356. //        Directory containing the bitmap if found, empty string otherwise.
  357. //
  358. {
  359.     string $directory = "", $file, $directoryArray[], $fileArray[];
  360.     int    $found = false;
  361.  
  362.     if ("" != $bitmap) {
  363.  
  364.         //    Get all the directories in the XBMLANGPATH environment variable.
  365.         //
  366.         $directoryArray = `xbmLangPathList`;
  367.  
  368.         for ($directory in $directoryArray) {
  369.             //
  370.             //    Make sure the directory ends in a "/" for the getFileList
  371.             //    command to work properly.
  372.             //
  373.             if (!`gmatch $directory "*/"`) $directory += "/";
  374.  
  375.             $fileArray = `getFileList -folder $directory`;
  376.  
  377.             //    Search for the bitmap.
  378.             //
  379.             for ($file in $fileArray) {
  380.                 if ($file == $bitmap) {
  381.                     $found = true;
  382.                     break;
  383.                 }
  384.             }
  385.  
  386.             if ($found) break;
  387.         }
  388.  
  389.         if (!$found) {
  390.             $directory = "";
  391.         }
  392.     }
  393.  
  394.     return $directory;
  395. }
  396.  
  397. global proc bitmapBrowserWindowDirectoryMenuChange()
  398. //
  399. //    Description:
  400. //        This procedure is called whenever the user changes the value of the
  401. //        directory option menu.
  402. //
  403. //        Update the finder control, file list and preview image.
  404. //
  405. {
  406.     string $directory;
  407.     
  408.     $directory = `optionMenu -query -value BitmapBrowserWindowDirectoryOptionMenu`;
  409.  
  410.     finder -edit -filePath $directory BitmapBrowserWindowFinder;
  411.  
  412.     updateDirectoryList("");
  413.     updatePreview();
  414. }
  415.  
  416. global proc bitmapBrowserWindowFinderChange()
  417. //
  418. //    Description:
  419. //        This procedure is called whenever the user changes the value of the
  420. //        finder control.
  421. //
  422. //        Update the file list and preview image.
  423. //
  424. {
  425.     updateDirectoryList("");
  426.     updatePreview();
  427. }
  428.  
  429. global proc bitmapBrowserWindowListSelect()
  430. //
  431. //    Description:
  432. //        This procedure is called whenever the user changes the selection in
  433. //        the file list.
  434. //
  435. //        Update the preview image.
  436. //
  437. {
  438.     updatePreview();
  439. }
  440.  
  441. global proc bitmapBrowserWindowCancel(string $callbackProcedure)
  442. //
  443. //    Description:
  444. //        This procedure is called whenever the user selects the Cancel button.
  445. //
  446. //        Invoke the callback procedure and close the browser.
  447. //
  448. {
  449.     string $bitmap;
  450.     int    $status = 0;
  451.  
  452.     if ("" != $callbackProcedure) {
  453.         eval ($callbackProcedure + " \"\" " + $status);
  454.     }
  455.  
  456.     bitmapBrowserWindowClose();
  457. }
  458.  
  459. global proc bitmapBrowserWindowSelect(string $callbackProcedure)
  460. //
  461. //    Description:
  462. //        This procedure is called whenever the user selects the Select button.
  463. //
  464. //        Invoke the callback procedure and close the browser.
  465. //
  466. {
  467.     string $bitmap;
  468.     int    $status = 0;
  469.  
  470.     if ("" != $callbackProcedure) {
  471.         $bitmap = getBitmapSelection();
  472.         
  473.         eval ($callbackProcedure + " \"" + $bitmap + "\" " + $status);
  474.     }
  475.  
  476.     bitmapBrowserWindowClose();
  477. }
  478.